from manager import Plugin


class CountHTTP301(Plugin):

    def __init__(self, **kwargs):
        self.keywords = ['counter']
        self.counter_301 = 0
        self.counter_total = 0

    def process(self, **kwargs):
        if 'status' in kwargs:
            self.counter_total += 1
            if kwargs['status'] == '301':
                self.counter_301 += 1

    def report(self, **kwargs):
        print('== HTTP code 301 counter ==')
        print(f"HTTP 301 responses: {self.counter_301}/{self.counter_total}")
        print(f"HTTP 301 percentage: {self.counter_301 / self.counter_total:.03%}")
        print()
